package com.vhall.component.framework.feignclient.core;

import org.springframework.aop.support.AopUtils;
import org.springframework.cglib.proxy.InvocationHandler;

import java.lang.reflect.Method;

public class FeignProxyInvocationHandler implements InvocationHandler {

    private Object target;

    public FeignProxyInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if ("toString".equals(method.getName())) {
            return AopUtils.getTargetClass(proxy).toString();
        }
        if ("equals".equals(method.getName())) {
            return method.invoke(AopUtils.getTargetClass(proxy), args);
        }
        if ("hashCode".equals(method.getName())) {
            return AopUtils.getTargetClass(proxy).hashCode();
        }
        return method.invoke(target, args);
    }
}
